<template>
  <div class="form-single-fragment" style="position: relative;">
    <el-form :model="achievement" label-width="100px" size="mini" label-position="right">
      <el-form-item label="文件名称">{{achievement.task}}</el-form-item>
      <el-form-item label="上传附件" prop="">
        <Upload v-model="achievement.accessoryList" fielState="11" :id="achievement.id" readonly></Upload>
        <!-- <div class="FileDoList" v-if="JSON.parse(achievement.accessoryList)">
          <div v-for="(item,index) in JSON.parse(achievement.accessoryList)" :key="index">
            <span>{{item.name}}</span>
            <b @click="filespreview(item)">预览</b>
            <strong @click="loadknowledgedownload(item)">下载</strong>
           </div>
        </div> -->
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { Administration } from '@/api/projectAdministration.js';
import Pdfpreview from '@/components/selector/Pdfpreview.vue';
import { getType } from '@/utils';
export default {
  name: 'AchievementsDetail',
  props: {
    achievement: {
      default: undefined
    }
  },
  data () {
    return {
      isShowloading: false,
      detailData: {},
      achievementFileVoList: []
    };
  },
  created () {
    console.log(this.achievement, 37)
    if (this.achievement) {
      let accessory = this.achievement?.accessoryList
      this.achievement.accessoryList = getType(accessory).isString ? JSON.parse(accessory) : accessory;
    }
  },
  computed: {
    isEdit () {
      return this.achievementsId != null && this.achievementsId !== '';
    }
  },
  mounted () {
    // this.loadDetailWidgetData()
  },
  methods: {
    /**
     * 项目成果详情
     */
    loadDetailWidgetData () {
      let params = {
        id: this.achievementsId
      };
      return new Promise((resolve, reject) => {
        Administration.achievementview(this, params).then(res => {
          this.detailData = res.data
          console.log(this.detailData, 57)
          this.achievementFileVoList = res.data.achievementFileVoList
        }).catch(e => {
          reject(e);
        });
      });
    },
    /**
     * pdf预览
     */
    filespreview (data) {
      let params = {
        files: data.pdfPath
      };
      this.$dialog.show(data.fileName, Pdfpreview, {
        area: ['100%', '100%']
      }, params).then(res => {
        this.loadknowledgedetail()
      }).catch(e => {
      });
    },
    /**
     * 文件下载
     */
    loadknowledgedownload (data) {
      if (data.fileType === 'jpg' || data.fileType === 'png') {
        window.open(data.pdfPath)
      } else {
        window.open(data.filePath)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.FileDoList{
  cursor: pointer;
  div{
    span{margin-right: 10px;}
    b{color: #409EFF;font-weight: normal;margin-right: 10px;}
    strong{color: #FF0000;font-weight: normal;}
  }
}
</style>
